<template>
  <div class="mod-config">
    <basic-container>
      <div class="boxsty zhiBiao">
        <div class="flex justifyContentSpaceBetween">
          <div class="tabletext">表单配置</div>
          <div class="tablelink">
            <el-button v-if="permissions.admin_sysformconf_add" icon="el-icon-plus" type="primary" @click="addOrUpdateHandle()">新增</el-button>
          </div>
        </div>

        <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()" class="form-inline">
          <el-form-item label="表单名称">
            <el-input v-model="dataForm.formName" placeholder="表单名称"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" type="primary" class="marginLeft" @click="getDataList()">检索</el-button>
          </el-form-item>
        </el-form>

        <div class="avue-crud">
          <el-table :data="dataList" border v-loading="dataListLoading">
            <el-table-column prop="" label="序号" header-align="center" align="center" :formatter="nShowIndex" width="70"></el-table-column>
            <el-table-column prop="formName" header-align="center" align="left" label="表单名称" width="180px"></el-table-column>
            <el-table-column prop="formSm" header-align="center" align="left" label="表单说明"></el-table-column>
            <el-table-column header-align="center" align="center" label="操作"  width="350px">
              <template slot-scope="scope">
                <el-button v-if="permissions.admin_sysformconf_edit" type="text" size="small" icon="el-icon-share" @click="designForm(scope.row.formId)" >配置</el-button>
                <el-button v-if="permissions.admin_sysformconf_edit" type="text" size="small" icon="el-icon-edit" @click="addOrUpdateHandle(scope.row.formId)">修改</el-button>
                <el-button v-if="permissions.admin_sysformconf_del" type="text" size="small" icon="el-icon-delete" @click="deleteHandle(scope.row.formId)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>

        <div class="avue-crud__pagination">
          <el-pagination
                  @size-change="sizeChangeHandle"
                  @current-change="currentChangeHandle"
                  :current-page="pageIndex"
                  :page-sizes="[10, 20, 50, 100]"
                  :page-size="pageSize"
                  :total="totalPage"
                  background
                  layout="total, sizes, prev, pager, next, jumper">
          </el-pagination>
        </div>
      </div>
      <!-- 弹窗, 新增 / 修改 -->
      <table-form v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></table-form>
      
    </basic-container>
    <design  v-if="designVisible" ref="design"></design>
  </div>
</template>

<script>
  import {fetchList, delObj} from '@/api/admin/sysformconf'
  import TableForm from './sysformconf-form'
  import design from './design'
  import {mapGetters} from 'vuex'
  export default {
    data () {
      return {
        dataForm: {
          formName: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        addOrUpdateVisible: false,
        designVisible:false,
      }
    },
    components: {
      TableForm,
      design
    },
    created () {
      this.getDataList()
    },
    computed: {
      ...mapGetters(['permissions'])
    },
    methods: {
      nShowIndex(row, column, cellValue, index) {
        return index + 1;
      },
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        fetchList(Object.assign({
          current: this.pageIndex,
          size: this.pageSize
        },this.dataForm)).then(response => {
          this.dataList = response.data.data.records
          this.totalPage = response.data.data.total
        })
        this.dataListLoading = false
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 删除
      deleteHandle (id) {
        this.$confirm('是否确认删除', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function () {
          return delObj(id)
        }).then(data => {
          this.$notify.closeAll();
          this.$notify.success('删除成功')
          this.getDataList()
        })
      },
    designForm(id){
      this.designVisible=true;
      this.$nextTick(()=>{
        this.$refs.design.getFormInfo(id);
      });
      
    }
    }
  }
</script>
